var pnum = "";  
var initData = function(num){
	    var param = {
			page_num:num,
			page_size:"10"
	    }
		$.ajax({
	        url: base + "/projectCenter/businessdata/findGyEquipmentList",
	        data: param,
	        success: function (data, textStatus, jqXHR) {
	        	if(data != null){
		        	var pageCount = data.pager.pageCount;
		        	var dataObj ={
		        			"list":data.list,
		         			"dataTool":{
		         				"title":{
		          			      	"manufacturer_equipment_name": "设备名称"
		          			      	,"equipment_price": "设备价格"
		          			      	,"equipment_power":"设备功率(kw)"
		          			      	,"equipment_model":"设备型号"
		          			      	,"equipment_manufacturer_name":"设备所属厂商名称"
		          			      	,"equipment_children_type_name":"使用场所"
		          			      	,"operation":"操作"
		            			},
		            			"titleCheckbox":false,
								"btn":[{"event":"showInfo","name":"查看设备详情"}]
							}
			  		};
		        	showPageTable('view', dataObj,num,pageCount,"initData");
	        	}
	        },
	        error: function () {
	        }
	    });
}

//初始化下拉选
var initSelect = function(){
	$.ajax({
		url:base + "/projectCenter/businessdata/findEquipmentTypeList",
		data:{},
        success: function (data, textStatus, jqXHR) {
        	if(data != null){
        		var list = data;
        		var options = "";
        		for(var i=0;i<list.length;i++){
        			options += "<option value='"+list[i].id+"'>"+list[i].equipment_children_type_name+"</option>";
        		}
        		$("#equipment_children_type_name").html(options);
        	}
        },
        error: function () {
        }
	});
}


var equipment_children_type_id = "";
//设备类型选择事件
var equipment_type_change = function(){
	   var val = $(this).children('option:selected').val();
	   equipment_children_type_id = val;
	   var text = $(this).children('option:selected').text();
	   if(val == ""){
		   initData(1);
	   }else{
		   showData(1);
	   }
}

//按条件查询
var showData = function(num){
    var param = {
			page_num:num,
			page_size:"10",
			equipment_children_type_id:equipment_children_type_id
	    }
	$.ajax({
        url: base + "/projectCenter/businessdata/findGyEquipmentList",
        data: param,
        success: function (data, textStatus, jqXHR) {
        	if(data != null){
	        	var pageCount = data.pager.pageCount;
	        	var dataObj ={
	        			"list":data.list,
	         			"dataTool":{
	         				"title":{
	          			      	"manufacturer_equipment_name": "设备名称"
	          			      	,"equipment_price": "设备价格"
	          			      	,"equipment_power":"设备功率(kw)"
	          			      	,"equipment_model":"设备型号"
	          			      	,"equipment_manufacturer_name":"设备所属厂商名称"
	          			      	,"equipment_children_type_name":"使用场所"
	          			      	,"operation":"操作"
	            			},
	            			"titleCheckbox":false,
							"btn":[{"event":"showInfo","name":"查看设备详情"}]
						}
		  		};
	        	showPageTable('view', dataObj,num,pageCount,"showData");
        	}
        },
        error: function () {
        }
    });
    
	
}

var searchObj = function(num){
    var param = {
			page_num:num,
			page_size:"10",
			equipment_name:$.trim($("#searchName").val())
	    }
	$.ajax({
        url: base + "/projectCenter/businessdata/findGyEquipmentList",
        data: param,
        success: function (data, textStatus, jqXHR) {
        	if(data != null){
	        	var pageCount = data.pager.pageCount;
	        	var dataObj ={
	        			"list":data.list,
	         			"dataTool":{
	         				"title":{
	          			      	"manufacturer_equipment_name": "设备名称"
	          			      	,"equipment_price": "设备价格"
	          			      	,"equipment_power":"设备功率(kw)"
	          			      	,"equipment_model":"设备型号"
	          			      	,"equipment_manufacturer_name":"设备所属厂商名称"
	          			      	,"equipment_children_type_name":"使用场所"
	          			      	,"operation":"操作"
	            			},
	            			"titleCheckbox":false,
	            			"btn":[{"event":"showInfo","name":"查看设备详情"}]
						}
		  		};
	        	showPageTable('view', dataObj,num,pageCount,"searchObj");
        	}
        },
        error: function () {
        }
    });
}

//显示设备详情
var showInfo = function(obj){
	var url = base + "/dataCenter/equipment/findEquipmentInfoById/"+obj.id;
	$.get(url,function(result){
		$(".right-article").html(result);
	});
}

$(document).ready(function(){
	 initData(1);
	 initSelect();
	 $("#equipment_children_type_name").change(equipment_type_change);
});